package com.google.code.roztocze358.client;
//package com.google.code.roztocze358.server;

import java.io.*;
import java.net.*;

public class TFESimpleClient {
    public static void main(String[] args) throws IOException {

        Socket tfeSocket = null;
        PrintWriter out = null;
        BufferedReader in = null;
        
        final String host = "localhost";
        final int port = 35853;

        try {
            tfeSocket = new Socket(host, port);
            out = new PrintWriter(tfeSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(tfeSocket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("Host " + host + " not find");
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to: " + host + ".");
            System.exit(1);
        }

        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        String serverMessage;
        String clientMessage;

        while ((serverMessage = in.readLine()) != null) {
            System.out.println("ServerMsg: " + serverMessage);
            if (serverMessage.equals("Sayonara."))
                break;
		    
            clientMessage = stdIn.readLine();
	    if (clientMessage != null) {
                System.out.println("ClientMsg: " + clientMessage);
                out.println(clientMessage);
	    }
        }

        out.close();
        in.close();
        stdIn.close();
        tfeSocket.close();
    }
}
